/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package docking;

import java.io.Serializable;
import java.util.ArrayList;

/**
 *
 * @author Jógvan
 */
public class Reservation implements Serializable {
    private Boat boat;
    private int fromYear;
    private int fromMonth;
    private int fromDay;
    private int fromHour;
    private int toYear;
    private int toMonth;
    private int toDay;
    private int toHour;
    private int reservationNumber;
    //private int blocks;
    private ArrayList<Service> serviceList;
    private Pier pier;
    
    
    public Reservation(Boat boat, int fromYear, int fromMonth, int fromDay,int fromHour, int toYear, int toMonth, int toDay,int toHour,int reservationNumber)
    {
        this.boat = boat; 
        this.fromYear = fromYear; 
        this.fromMonth = fromMonth; 
        this.fromDay = fromDay ;
        this.fromHour = fromHour; 
        this.toYear  = toYear;
        this.toMonth = toMonth ;
        this.toDay = toDay ;
        this.toHour = toHour;
        this.reservationNumber = reservationNumber;
        serviceList = new ArrayList<Service>();
    }
    
    /**
     * roknar prísin
     */
    public int getPrice()
    {
        int numberOfBlocks = getNumberrOfBlocks();
       
        
        //Manglar BTR 
        int cost = 1000 + pier.getPrice() * numberOfBlocks * pier.getLengthOfBlock() * calculateHours();
        
        // addar prive hjá service
        cost += servicePrice();
        
        return cost;
    }
    
    
    public int getNumberrOfBlocks()
    {
        int numberOfBlocks = 0;
        if(boat.getLength() % pier.getLengthOfBlock() == 0)
        {
            numberOfBlocks = boat.getLength() / pier.getLengthOfBlock();
        }
        else{
        
            numberOfBlocks = boat.getLength() / pier.getLengthOfBlock()+1;
        }
        return numberOfBlocks;
    }
    /**
     * roknar longdina hjá reservatiónuni, skal brúkast til at rokna prísin
     * 
     * @return Hour length of reservation 
     */
    private int calculateHours()
    {
        int year = toYear - fromYear;
        int month = toMonth - fromMonth;
        int day = toDay - fromDay;
        int hour = toHour - fromHour;
    
        int total = year * 8760;
        total += month * 744;
        total += day * 24;
        total += hour;
        
        return total;
    }
    
    private int servicePrice()
    {
        int price = 0;
        for(Service s : serviceList)
        {
            price += s.getPrice();
        }
        return price;
    }
    
    public void setPier(Pier p)
    {
        pier = p;
    }
    
    
    /**
     * Returnar Boat sum hevur bestilt hesa Resevation
     * 
     * @return Boat
     */
    public Boat getBoat()
    {
        return boat;
    }
    
    /**
     * Overridar toString, til at returna ResevatiónsNummar
     * @return 
     */
    public String toString()
    {
        return reservationNumber+"";
    }
    
    /**
     * returnerar ein string av Date, tvs vit leggja from*** saman
     * 
     * @return String fromDate
     */
    public String reservationDateStringFrom()
    {
        return getFromDay() + " / " + getFromMonth() + " - " + getFromYear() + "  KL " + getFromHour() + ":00";
    }
    
    /**
     * returnerar ein string av Date, tvs vit leggja to*** saman
     * 
     * @return String toDate
     */
    public String reservationDateStringTo()
    {
        return toDay + " / " + toMonth + " - " + toYear + "  KL " + toHour + ":00";
    }
    
    /**
     * addar service til listan av services hjá Reservatiónuni
     * 
     * @param service 
     */
    public void addService(Service service)
    {
        serviceList.add(service);
    }
    
    /**
     * returnar ArrayList av Services sum hendan Reservatió hevur bestilt
     * @return serviceList
     */
    public ArrayList<Service> getServiceList()
    {
        return serviceList;
    }

    /**
     * @return the fromYear
     */
    public int getFromYear() {
        return fromYear;
    }

    /**
     * @return the fromMonth
     */
    public int getFromMonth() {
        return fromMonth;
    }

    /**
     * @return the fromDay
     */
    public int getFromDay() {
        return fromDay;
    }
    
    /**
     * @return the fromHour
     */
    public int getFromHour() {
        return fromHour;
    }

     /**
     * @return the toYear
     */
    public int getToYear() {
        return toYear;
    }

    /**
     * @return the tomMonth
     */
    public int getToMonth() {
        return toMonth;
    }

    /**
     * @return the toDay
     */
    public int getToDay() {
        return toDay;
    }
}
